<?php

namespace App\Admin\Controllers\Common;

use App\Models\CommonAppAgreement;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class AppAgreementController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = 'APP协议信息';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new CommonAppAgreement());

        $grid->column('id', ___('table.zy_common_app_agreement.Id'));
        $grid->column('title', ___('table.zy_common_app_agreement.Title'));
        $grid->column('content', ___('table.zy_common_app_agreement.Content'))->display(function ($data){
            return mb_strlen(trim($data)) > 10 ? mb_substr($data, 0, 10).'...' : $data;
        });
        $grid->column('create_time', ___('table.zy_common_app_agreement.Create time'));
        $grid->column('update_time', ___('table.zy_common_app_agreement.Update time'));

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(CommonAppAgreement::findOrFail($id));

        $show->field('id', ___('table.zy_common_app_agreement.Id'));
        $show->field('title', ___('table.zy_common_app_agreement.Title'));
        $show->field('content', ___('table.zy_common_app_agreement.Content'));
        $show->field('create_time', ___('table.zy_common_app_agreement.Create time'));
        $show->field('update_time', ___('table.zy_common_app_agreement.Update time'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new CommonAppAgreement());

        $form->text('title', ___('table.zy_common_app_agreement.Title'));
        $form->textarea('content', ___('table.zy_common_app_agreement.Content'));
        $form->number('create_time', ___('table.zy_common_app_agreement.Create time'));
        $form->number('update_time', ___('table.zy_common_app_agreement.Update time'));

        return $form;
    }
}
